﻿
@using Blazor.Diagrams.Components
@using AntDesign
@using AntDesign.ProLayout
@using AntDesign.Core
@using AntDesign.TableModels
@using Blazor.Diagrams.Core.Models
@using  ERP.Workflow.Designer.BlazorUI.Models



@implements IPropertyBox<FlowLink>

<Tabs  Animated  Centered  @bind-ActiveKey="@activeKey"     >
	  <TabPane Tab="基本信息" Key="1"  >
                <Row  Class="row">
                      <AntDesign.Col Span="10"  Class="col l"><lable class="lable">名称</lable></AntDesign.Col>
                      <AntDesign.Col Span="14" Class="col">
                           <Input Size="small" style="width:120px;"  @bind-Value="Lable.Content" TValue="string"  OnChange="@((e)=>{change(nameof(FlowLink.Content),e);})"></Input>
                        </AntDesign.Col>       
                 </Row>  
                  <Row  Class="row">
                      <AntDesign.Col Span="10"  Class="col l"><lable class="lable">迁移表达式</lable></AntDesign.Col>
                      <AntDesign.Col Span="14" Class="col">
                           <Input Size="small" style="width:120px;"  @bind-Value="Data.Expression" TValue="string"  OnChange="@((e)=>{change(nameof(FlowLink.Expression),e);})"></Input>
                        </AntDesign.Col>       
                 </Row>  
        </TabPane>
       
</Tabs>
@code {
    [CascadingParameter] Diagram Diagram { get; set; }
    [Parameter] public FlowLink? Data { get; set; }
    [Parameter] public EventCallback<PropertyChangeEventArg> OnChange { get; set; }

    protected string activeKey = TabItems.BaseInfo;

    protected LinkLabelModel? Lable;

    protected override Task OnInitializedAsync()
    {

        Lable = Data!.Labels.FirstOrDefault();
        if (Lable == null)
        {
            Lable = new LinkLabelModel(Data, "迁移名称");
            Data.Labels.Add(Lable);
        }
        return base.OnInitializedAsync();
    }

    public virtual void Refresh()
    {
        Lable =  Data!.Labels.FirstOrDefault();
        if (Lable == null)
        {
            Lable = new LinkLabelModel(Data, "迁移名称");
            Data.Labels.Add(Lable);
        }
        StateHasChanged();
    }
    protected void change(string field,string val)
    {
        OnChange.InvokeAsync(new PropertyChangeEventArg { Data = Data, FieldName = field, Value = val });
        if (field == nameof(FlowLink.Content))
            Data!.Content = string.Join(",", Data.Labels.Select(m => m.Content));
    }
}
